using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxPro;

using CMS.Core.DataInterfaces;
using CMS.Data;
using CMS.Core.Domain;
using CMS.Presenters.Presenters;
using CMS.Presenters.Views;
using CMS.Data.Common;
using System.Collections.Generic;

namespace CMS.Web.ListManager
{
    public partial class AddPhongBan : BaseUserControl, IAddPhongBanView
    {
        private AddPhongBanPresenter presenter;
        // For Nguoi su dung

        public AddPhongBan()
        {
            this.presenter = new AddPhongBanPresenter(this, NHibernateDaoFactory.Instance.GetPhongBanDao());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // For Ajax
            this.RaiseClientEvent();
            if (!this.IsPostBack)
            {
                // For Nguoi su dung
                //this.drpNguoiSuDung.DataSource = this.NguoiSuDungList;
                //drpNguoiSuDung.DataTextField = "TenNguoiSuDung";
                //drpNguoiSuDung.DataValueField = "ID";
                //this.drpNguoiSuDung.DataBind();
                this.txtSTT.Text = Convert.ToString(presenter.GetMaxSTT());
            }
            //this.btnOK.Attributes.Add("onclick", "return CheckInput(0);");
            //this.btnOKC.Attributes.Add("onclick", "return CheckInput(1);");
        }

        // For Ajax to validdate
        protected void RaiseClientEvent()
        {
            Utility.RegisterTypeForAjax(typeof(CMS.Presenters.Presenters.AddPhongBanPresenter));
        }

        public string Message
        {
            set { //lblMessage.Text = value; 
            }
        }

        public PhongBan PhongBanToAdd
        {
            get
            {
                PhongBan obj = new PhongBan();
                obj.TenPhongBan = txtName.Text.Trim();
                if ((txtSTT.Text.Trim() != null) && (!txtSTT.Text.Trim().Equals("")))
                {
                    obj.ThuTu = Convert.ToByte(txtSTT.Text.Trim());
                }
                obj.TrangThai = Convert.ToBoolean(radStatus.SelectedValue);
                return obj;
            }
        }       

        protected void btnOK_Click(object sender, EventArgs e)
        {
            presenter.AddObj(Page.IsValid);
            this.btnCancel_Click(this, null);
        }

        protected void btnOKC_Click(object sender, EventArgs e)
        {
            presenter.AddObj(Page.IsValid);
            this.txtName.Text = "";
            this.txtName.Focus();
            this.txtSTT.Text = Convert.ToString(presenter.GetMaxSTT());
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(this.BaseUrl + "&action=VIEW");
        }
    }
}